﻿-- Function: pl_function.listar_declaraciones(character varying, refcursor)

-- DROP FUNCTION pl_function.listar_declaraciones(character varying, refcursor);

CREATE OR REPLACE FUNCTION pl_function.listar_declaraciones(p_mperson character varying, p_ref refcursor)
  RETURNS refcursor AS
$BODY$
begin
	open p_ref for select vnrodoc, vmotivo, mhresum, cidpers, mobserv as vobserv, to_char(dfecdoc, 'dd/mm/yyyy') dfecdoc
	from registro.vwhresum where cidpers=p_mperson and ctippro='1000000451'
	group by vnrodoc, vmotivo, mhresum, cidpers, mobserv, to_char(dfecdoc, 'dd/mm/yyyy')
	order by mhresum desc;
	return p_ref;
end
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION pl_function.listar_declaraciones(character varying, refcursor)
  OWNER TO postgres;
GRANT EXECUTE ON FUNCTION pl_function.listar_declaraciones(character varying, refcursor) TO postgres;
GRANT EXECUTE ON FUNCTION pl_function.listar_declaraciones(character varying, refcursor) TO public;
GRANT EXECUTE ON FUNCTION pl_function.listar_declaraciones(character varying, refcursor) TO desarrollo;
